import $tools from '@/utils/tools';

const domain = "https://bdb24c6d-8c19-4f80-8e7e-c9c9f037f131.bspapp.com";

const request = (options = {}) => {

	return new Promise((resolve, reject) => {
		uni.request({
			url: domain + options.url || '',
			method: options.method || 'GET',
			data: options.data || {},
			header: {
				"Authorization": uni.getStorageSync('toekn')||'',
				'content-type': "application/json",
			},
			success(res) {
				if(res.statusCode===200){
					resolve(res.data)
				}else{
					$tools.toast(res.errMsg)
				}
			},
			fail(err) {
				console.log(err)
			}
		})
	})
}

// GET请求
const get = (url, data = {}, options = {}) => {
	options.url = url
	options.method = 'GET'
	options.data = data
	return request(options)
}

// POST请求
const post = (url, data = {}, options = {}) => {
	options.url = url
	options.method = 'POST'
	options.data = data
	return request(options)
}

// 默认向外暴露的数据
export default {
	request,
	get,
	post
}
